package dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import model.VoyageAvion;

@Stateless
public class VoyageAvionDaoImpl implements IVoyageAvionDao {

	@PersistenceContext(unitName = "putravel")
	EntityManager em;

	@Override
	public void add(VoyageAvion voyageavion) {
		em.persist(voyageavion);
	}

	@Override
	public VoyageAvion find(String depart, String date) {
		VoyageAvion result;
		Query q = em
				.createQuery("select v from VoyageAvion v where v.villeDepart.nomVille=:depart and v.dateVol=:date");
		q.setParameter("depart", depart);
		q.setParameter("date", date);
		try {
			result = (VoyageAvion) q.getSingleResult();
			return result;
		} catch (javax.persistence.NoResultException e) {
			return null;
		}
	}

}
